<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0"
    />
    <style type="text/css">
      html,
      body {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        margin: 0;
        padding: 0;
      }
      button {
        display: block;
        width: 100%;
        padding: 20px;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <script src="./jsbridge.js"></script>
    <script type="text/javascript">
      function onClickButton(button) {
        switch (button.innerText) {
          case "UI.toast":
            JSBridge.UI.toast("This is toast!")
            break
          case "UI.alert":
            JSBridge.UI.alert({
              title: '通知',
              message: '这是一条Alert',
              button: "好"
            })
            break
          case "UI.confirm":
            JSBridge.UI.confirm({
              title: '请确认',
              message: '你认识mingo吗？',
              buttons: [
                "不确定",
                "不认识",
                "认识"
              ]
            }, (button) => {
              JSBridge.UI.toast("选择了：" + button)
            })
            break
          case "KVDB.getInt":
            JSBridge.KVDB.getInt("int", (result) => {
              JSBridge.UI.toast("getInt：" + result)
            })
            break
          case "KVDB.setInt":
            JSBridge.KVDB.setInt("int", parseInt(Date.now() / 1000))
            JSBridge.UI.toast('setInt')
            break
          case "KVDB.getBool":
            JSBridge.KVDB.getBool("bool", (result) => {
              JSBridge.UI.toast("getBool: " + result)
            })
            break
          case "KVDB.setBool":
            JSBridge.KVDB.setBool("bool", Date.now() % 2 === 0)
            JSBridge.UI.toast('setBool')
            break
          case "KVDB.getString":
            JSBridge.KVDB.getString("string", (result) => {
              JSBridge.UI.toast("getString: " + result)
            })
            break
          case "KVDB.setString":
            JSBridge.KVDB.setString("string", "string_value_" + Date.now())
            JSBridge.UI.toast('setString')
            break
          case "KVDB.getJSON":
            JSBridge.KVDB.getJSON("json", (result) => {
              JSBridge.UI.toast("getJSON: " + JSON.stringify(result, null, '  '))
            })
            break
          case "KVDB.setJSON":
            JSBridge.KVDB.setJSON("json", { title: 'This is json', message: 'time is ' + new Date().toUTCString() })
            JSBridge.UI.toast('setJSON')
            break
          case "Camera.takePicture":
            JSBridge.Camera.takePicture((result) => {
              JSBridge.UI.toast(JSON.stringify(result))
            })
            break
          case "Camera.takeVideo":
            JSBridge.Camera.takeVideo((result) => {
              JSBridge.UI.toast(JSON.stringify(result))
            })
            break
          case "Image.pickPhotos":
            JSBridge.Image.pickPhotos((result) => {
              JSBridge.UI.toast(JSON.stringify(result))
            })
            break
        }
      }
    </script>
    <button onclick="onClickButton(this)">UI.toast</button>
    <button onclick="onClickButton(this)">UI.alert</button>
    <button onclick="onClickButton(this)">UI.confirm</button>
    <button onclick="onClickButton(this)">KVDB.getInt</button>
    <button onclick="onClickButton(this)">KVDB.setInt</button>
    <button onclick="onClickButton(this)">KVDB.getBool</button>
    <button onclick="onClickButton(this)">KVDB.setBool</button>
    <button onclick="onClickButton(this)">KVDB.getString</button>
    <button onclick="onClickButton(this)">KVDB.setString</button>
    <button onclick="onClickButton(this)">KVDB.getJSON</button>
    <button onclick="onClickButton(this)">KVDB.setJSON</button>
    <button onclick="onClickButton(this)">Camera.takePicture</button>
    <button onclick="onClickButton(this)">Camera.takeVideo</button>
    <button onclick="onClickButton(this)">Image.pickPhotos</button>
  </body>
  </body>
</html>
